package com.lgc.netdemo.config

import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

/**
 * okhttp的重试拦截器
 */
class RetryInterceptor(private val maxRetry:Int=0):Interceptor {
    private var retriedNum:Int=0//已经重试的次数，注意
    override fun intercept(chain: Interceptor.Chain): Response {
        val request: Request =chain.request()
        var response:Response=chain.proceed(request)
        while(!response.isSuccessful && retriedNum<maxRetry){
            retriedNum++
            response=chain.proceed(request)
        }
        return response
    }
}